home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 December / PC Answers December 1995 (disc errors).iso / hobby / editbox / devel300 / st-wnd-m.c < prev   
Encoding:
C/C++ Source or Header  |  1995-08-14  |  27.4 KB  |  638 lines

  1. /**************************************************************************************************
  2.  
  3.     SPELTEST
  4.     Program to test spelling checker.
  5.  
  6.     Written and copyright by Brian J Quinion 1995.
  7.  
  8.     Version for Microsoft Windows.
  9.     Version:  0.01 (Production)
  10.     Date:     19 Feb 1995
  11.     Module:   ST-WND-M.C
  12.  
  13. **************************************************************************************************/
  14.  
  15.     /* include files common to all modules */
  16. #define EXTERN extern
  17.     #include "speltest.h"
  18.  
  19.     /* include files for this module only */
  20.     #pragma  hdrstop
  21.     /* NONE */
  22.  
  23.     // Some text to check
  24.     static char                 Words[6][15]={"thiss",
  25.                                             "poeple",
  26.                                             "aggrivation",
  27.                                             "enviromental",
  28.                                             "wheight",
  29.                                             "nohting"};
  30.  
  31. /***************************************************************************************************
  32.  
  33.     RegisterSPELTEST_MAIN
  34.     ---------------------
  35.     Register window class 'SPELTEST_MAIN'
  36.  
  37.     Parameters : None
  38.     Called by  : WinMain on initialisation
  39.     Calls      : Nothing
  40.     Modifies   : Nothing
  41.     Returns    : Nothing
  42.  
  43. ***************************************************************************************************/
  44. void RegisterSPELTEST_MAIN(void)
  45. {
  46.     WNDCLASS    wndclass;
  47.  
  48.     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  49.     wndclass.lpfnWndProc   = (WNDPROC)SPELTEST_MAINWndProc;
  50.     wndclass.cbClsExtra    = 0;
  51.     wndclass.cbWndExtra    = 0;
  52.     wndclass.hInstance     = g.hInst;
  53.     wndclass.hIcon         = LoadIcon(g.hInst, "ICON_1");
  54.     wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  55.     wndclass.hbrBackground = CreateSolidBrush(RGB(0,0,0));
  56.     wndclass.lpszMenuName  = "SPELTEST_MAIN";
  57.     wndclass.lpszClassName = "SPELTEST_MAIN";
  58.     RegisterClass(&wndclass);
  59. }
  60.  
  61. /***************************************************************************************************
  62.  
  63.     SPELTEST_MAINWndProc
  64.     -----------------
  65.     To handle messages to 'SPELTEST_MAIN' class
  66.  
  67.     Parameters : WND standard
  68.     Called by  : Windows
  69.     Calls      : 
  70.     Modifies   : 
  71.     Returns    : Depends on calling parameters
  72.  
  73. ***************************************************************************************************/
  74. #pragma argsused
  75. long FAR PASCAL SPELTEST_MAINWndProc(HWND hWnd, UINT wMsg, WORD wParam, LONG lParam)
  76. {
  77.     PAINTSTRUCT            ps;
  78.  
  79. // Quick
  80.     static HWND                 hWndEdit;
  81.     HGLOBAL                     hmemEdit;
  82.     LPSTR                       lpmemEdit;
  83.     WORD                        wSize;
  84.  
  85. // Full - see how much more of it there is! :-)
  86.     CHECKWORD                   CheckWord;
  87.     LPCHECKWORD                 lpchkw;
  88.     WORD                        wIndex;
  89.     char                        Text[100];
  90.     static BOOL                 bCanUndo;
  91.     static HUNDO                hUndoHandle;
  92.     static WORD                 wUndoIndex;
  93.     static char                 szPreviousWord[MAXSPELL];
  94.  
  95.     switch(wMsg)
  96.     {
  97.     case WM_CREATE:
  98.         hWndEdit=CreateWindow("EDIT", NULL, ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_NOHIDESEL | ES_OEMCONVERT | ES_WANTRETURN | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP,
  99.                              0, 0, 400, 200, hWnd, -1, g.hInst, NULL);
  100.         break;
  101.         
  102.     case WM_PAINT:
  103.         // kill paint messages to stop them looping
  104.         BeginPaint(hWnd, &ps);
  105.         EndPaint(hWnd, &ps);
  106.         return 0;
  107.  
  108.     case WM_SYSCOLORCHANGE:
  109.         return 0;
  110.  
  111.     case WM_COMMAND:
  112.         switch(wParam)
  113.         {
  114.         // Quick 
  115.         case MLC_CHECKEDIT:
  116.             (g.LINK_SPEDT_CheckEdit)(hWndEdit); // spell check the edit box
  117.             return 0;
  118.  
  119.         case MLC_CHECKEDITCUSTOM:
  120.             (g.LINK_SPEDT_CheckEditCustom)(hWndEdit, g.hInst, "EditCustom", NULL);
  121.             return 0;
  122.  
  123.         case MLC_CHECKEDITGLOBAL:
  124.             // How much space for the edit control?
  125.             wSize=SendMessage(hWndEdit, WM_GETTEXTLENGTH, 0, 0L);
  126.             // Aloccate enough global memory to hold the text, plus a bit to give some
  127.             // room for changes (if there is not enough it will be changed by spelledt)
  128.             hmemEdit=GlobalAlloc(GHND, wSize+100);
  129.             lpmemEdit=GlobalLock(hmemEdit);
  130.             // Copy in the text
  131.             SendMessage(hWndEdit, WM_GETTEXT, wSize+1, (LPARAM)lpmemEdit);
  132.             // The data MUST be unlocked
  133.             GlobalUnlock(hmemEdit);
  134.             // Do the check
  135.             (g.LINK_SPEDT_CheckGlobal)(hWnd, &hmemEdit, RegisterClipboardFormat("HTML Text Format"), NULL);
  136.             // Put the data back in the edit box
  137.             lpmemEdit=GlobalLock(hmemEdit);
  138.             SendMessage(hWndEdit, WM_SETTEXT, 01, (LPARAM)lpmemEdit);
  139.             GlobalUnlock(hmemEdit);
  140.             // and junk the global memory
  141.             GlobalFree(hmemEdit);
  142.             MessageBeep(-1);
  143.             return 0;
  144.  
  145.         // Full
  146.         case MLC_CHECKWORDS:
  147.             // Build the checkword block
  148.              CheckWord.wSizeOfBlock     = sizeof(CHECKWORD);
  149.             CheckWord.hWndParent       = hWnd;  // window that msg are sent to
  150.             CheckWord.CheckWordOptions = CWO_ALLOWCHANGE    // Do display the box if a word not found
  151.                                        | CWO_CHECKMULTIPLE  // Send GETNEXT messages
  152.                                        | CWO_NOHELP         // No help available
  153.                                        | CWO_UNDO           // Undo is handled
  154.                                        | CWO_AUTOSUGGEST;    // Please auto suggest
  155.             CheckWord.dwCustData  = 0; // Index of the first word to check
  156.             // Get the current language from the one selected by spelledt
  157.             GetPrivateProfileString("Options", "Language", "", CheckWord.szLanguage, 13, "spelledt.ini");
  158.             // Load custom dictionaries, in this case we will share the ones that are used by
  159.             LoadCustomDictionaries(&CheckWord);
  160.             // spell check the edit box
  161.             (g.LINK_SPCHK_CheckWord)(&CheckWord);
  162.             // Store the language
  163.             WritePrivateProfileString("Options", "Language", CheckWord.szLanguage, "spelledt.ini");
  164.             // Save any changes to the custom dics
  165.             SaveCustomDictionaries(&CheckWord);
  166.             return 0;
  167.  
  168.         case MLC_CHECKWORDSCUSTOM:
  169.             // Build the checkword block
  170.              CheckWord.wSizeOfBlock     = sizeof(CHECKWORD);
  171.             CheckWord.hWndParent       = hWnd;  // window that msg are sent to
  172.             CheckWord.hInstance        = g.hInst;
  173.             CheckWord.lpMainDlg        = "EditCustom";
  174.             CheckWord.lpOptionsDlg     = "SetupFullCustom";
  175.             CheckWord.CheckWordOptions = CWO_ALLOWCHANGE    // Do display the box if a word not found
  176.                                        | CWO_CHECKMULTIPLE  // Send GETNEXT messages
  177.                                        | CWO_NOHELP         // No help available
  178.                                        | CWO_UNDO           // Undo is handled
  179.                                        | CWO_USECUSTOMMAINDLG // and use our dialog box
  180.                                        | CWO_USEOPTIONSHOOK // Do use the options hook
  181.                                        | CWO_USECUSTOMOPTIONSDLG // and use our dialog box 
  182.                                        | CWO_AUTOSUGGEST;    // Please auto suggest
  183.              CheckWord.fpOptionsHook  = (DLGPROC)MakeProcInstance(DLG_OptionsBox, g.hInst);
  184.             CheckWord.dwCustData  = 0; // Index of the first word to check
  185.             // Get the current language from the one selected by spelledt
  186.             GetPrivateProfileString("Options", "Language", "", CheckWord.szLanguage, 13, "spelledt.ini");
  187.             // Load custom dictionaries, in this case we will share the ones that are used by
  188.             LoadCustomDictionaries(&CheckWord);
  189.             // spell check the edit box
  190.             (g.LINK_SPCHK_CheckWord)(&CheckWord);
  191.             // Free ProcInstance for the options hook
  192.             FreeProcInstance(CheckWord.fpOptionsHook);
  193.             // Store the language
  194.             WritePrivateProfileString("Options", "Language", CheckWord.szLanguage, "spelledt.ini");
  195.             // Save any changes to the custom dics
  196.             SaveCustomDictionaries(&CheckWord);
  197.             return 0;
  198.  
  199.         // Setup
  200.         case MLC_SETUPQUICK:
  201.             (g.LINK_SPEDT_SetupBox)(hWndEdit);
  202.             return 0;
  203.  
  204.         case MLC_SETUPQUICKLIMITED:
  205.             (g.LINK_SPEDT_SetupBoxLimited)(hWndEdit);
  206.             return 0;
  207.  
  208.         case MLC_SETUPQUICKCUSTOM:
  209.             (g.LINK_SPEDT_SetupCustom)(hWndEdit, g.hInst, "SetupQuickCustom");
  210.             return 0;
  211.  
  212.         case MLC_SETUPFULL:
  213.             memset(&CheckWord, 0, sizeof(CheckWord));
  214.               CheckWord.wSizeOfBlock     = sizeof(CHECKWORD);
  215.             CheckWord.hWndParent       = hWndEdit;  // window that msg are sent to
  216.             CheckWord.CheckWordOptions = CWO_NOHELP         // No help available
  217.                                        | CWO_AUTOSUGGEST;    // Please auto suggest
  218.             // Get the current language from the one selected by spelledt
  219.             GetPrivateProfileString("Options", "Language", "", CheckWord.szLanguage, 13, "spelledt.ini");
  220.             // Load custom dictionaries, in this case we will share the ones that are used by
  221.             LoadCustomDictionaries(&CheckWord);
  222.             // Show the options box
  223.             (g.LINK_SPCHK_Options)(&CheckWord);
  224.             // Store the language
  225.             WritePrivateProfileString("Options", "Language", CheckWord.szLanguage, "spelledt.ini");
  226.             // Save any changes to the custom dics
  227.             SaveCustomDictionaries(&CheckWord);
  228.             return 0;
  229.  
  230.         case MLC_SETUPFULLCUSTOM:
  231.             memset(&CheckWord, 0, sizeof(CheckWord));
  232.               CheckWord.wSizeOfBlock     = sizeof(CHECKWORD);
  233.             CheckWord.hWndParent       = hWndEdit;  // window that msg are sent to
  234.             CheckWord.hInstance        = g.hInst;
  235.             CheckWord.lpOptionsDlg     = "SetupFullCustom";
  236.             CheckWord.CheckWordOptions = CWO_NOHELP         // No help available
  237.                                        | CWO_USEOPTIONSHOOK // Do use the options hook
  238.                                        | CWO_USECUSTOMOPTIONSDLG // and use our dialog box 
  239.                                        | CWO_AUTOSUGGEST;    // Please auto suggest
  240.              CheckWord.fpOptionsHook  = (DLGPROC)MakeProcInstance(DLG_OptionsBox, g.hInst);
  241.             // Get the current language from the one selected by spelledt
  242.             GetPrivateProfileString("Options", "Language", "", CheckWord.szLanguage, 13, "spelledt.ini");
  243.             // Load custom dictionaries, in this case we will share the ones that are used by
  244.             LoadCustomDictionaries(&CheckWord);
  245.             // Show the options box
  246.             (g.LINK_SPCHK_Options)(&CheckWord);
  247.             // Free ProcInstance for the options hook
  248.             FreeProcInstance(CheckWord.fpOptionsHook);
  249.             // Store the language
  250.             WritePrivateProfileString("Options", "Language", CheckWord.szLanguage, "spelledt.ini");
  251.             // Save any changes to the custom dics
  252.             SaveCustomDictionaries(&CheckWord);
  253.             return 0;
  254.  
  255. /*        case MLC_CHECKWORDS:
  256.             // Build the checkword block
  257.         CheckWord.wSizeOfBlock     = sizeof(CHECKWORD);
  258.         CheckWord.hWndParent       = hWnd;  // window that msg are sent to
  259.         CheckWord.hInstance        = g.hInst;
  260.         CheckWord.lpOptionsDlg     = "SPELTEST_OPTIONSBOX";
  261.         CheckWord.CheckWordOptions = CWO_ALLOWCHANGE    // Do display the box if a word not found
  262.                                        | CWO_CHECKMULTIPLE  // Send GETNEXT messages
  263.                                        | CWO_USEOPTIONSHOOK // Do use the options hook
  264.                                        | CWO_USECUSTOMOPTIONSDLG // and use our dialog box 
  265.                                        | CWO_NOHELP         // No help available
  266.                                        | CWO_UNDO           // Undo is handled
  267.                                        | CWO_AUTOSUGGEST;    // Please auto suggest
  268.         CheckWord.dwCustData  = 0; // Index of the first word to check
  269.         CheckWord.fpOptionsHook  = (DLGPROC)MakeProcInstance(DLG_OptionsBox, g.hInst);
  270.  
  271.             // Get the current language from the one selected by spelledt
  272.         GetPrivateProfileString("Options", "Language", "", CheckWord.szLanguage, 13, "spelledt.ini");
  273.  
  274.         // Load custom dictionaries, in this case we will share the ones that are used by
  275.             // spelledt (i.e. the edit box one).
  276.         CheckWord.NumCustom=GetPrivateProfileInt("Custom", "Number", 0, "spelledt.ini");
  277.         CheckWord.CurCustom=GetPrivateProfileInt("Custom", "Current", 0, "spelledt.ini");
  278.         if (CheckWord.NumCustom!=0)
  279.             {
  280.         CheckWord.hCustomDics = GlobalAlloc(GHND | GMEM_DDESHARE, sizeof(CUSTDIC)*CheckWord.NumCustom);
  281.         lpCustDic = (LPCUSTDIC)GlobalLock(CheckWord.hCustomDics);
  282.         for (Count=0; Count<CheckWord.NumCustom; Count++)
  283.             {
  284.             itoa(Count, GetCustPath+4, 10);
  285.             itoa(Count, GetCustName+4, 10);
  286.             itoa(Count, GetCustOpts+4, 10);
  287.             GetPrivateProfileString("Custom", GetCustPath, "custom.dic", (lpCustDic+Count)->DicFile, MAXPATH, "spelledt.ini");
  288.             GetPrivateProfileString("Custom", GetCustName, "Custom", (lpCustDic+Count)->DicTitle, MAXDICTITLE, "spelledt.ini");
  289.             (lpCustDic+Count)->Options=GetPrivateProfileInt("Custom", GetCustOpts, CD_CHANGED, "spelledt.ini");
  290.         }
  291.         GlobalUnlock(CheckWord.hCustomDics);
  292.             }
  293.  
  294.             // Reset the undo pointer
  295.             bCanUndo=FALSE;
  296.  
  297.             // Load the checkchk module.
  298.  
  299.             // Get the path and try to load the module
  300.             GetPrivateProfileString("Modules", "spellchk", "spellchk.dll", FileName, MAXPATH, "Spelledt.ini");
  301.             hModSpellchk=LoadLibrary(FileName);
  302.             if (hModSpellchk<HINSTANCE_ERROR)
  303.             {
  304.                 MessageBox(hWnd, "Unable to load the module 'spellchk.dll'", "Spell setup", MB_ICONSTOP);
  305.                 return 0;
  306.             }
  307.  
  308.             // Get the address of the function and call it
  309.             (FARPROC)LINK_SPCHK_CheckWord=GetProcAddress(hModSpellchk, "SPCHK_CheckWord");
  310.             if (LINK_SPCHK_CheckWord==NULL)
  311.                 MessageBox(hWnd, "Unable to load the function 'SPCHK_CheckWord', probably due to an incompatable version.  Please check your system for multiple versions of 'spellchk.dll'.", "Spell setup", MB_ICONSTOP);
  312.             else
  313.                 (LINK_SPCHK_CheckWord)(&CheckWord); // spell check the edit box
  314.  
  315.             // Free the module
  316.             FreeModule(hModSpellchk);
  317.  
  318.         // Free ProcInstance for the options hook
  319.         FreeProcInstance(CheckWord.fpOptionsHook);
  320.  
  321.             // Store the language
  322.         WritePrivateProfileString("Options", "Language", CheckWord.szLanguage, "spelledt.ini");
  323.  
  324.         // Save any changes to the custom dics
  325.         lpCustDic = (LPCUSTDIC)GlobalLock(CheckWord.hCustomDics);
  326.         WritePrivateProfileInt("Custom", "Number", CheckWord.NumCustom, "spelledt.ini");
  327.         WritePrivateProfileInt("Custom", "Current", CheckWord.CurCustom, "spelledt.ini");
  328.         for (Count=0; Count<CheckWord.NumCustom; Count++)
  329.         {
  330.         itoa(Count, GetCustPath+4, 10);
  331.         itoa(Count, GetCustName+4, 10);
  332.         itoa(Count, GetCustOpts+4, 10);
  333.         WritePrivateProfileString("Custom", GetCustPath, (lpCustDic+Count)->DicFile, "spelledt.ini");
  334.         WritePrivateProfileString("Custom", GetCustName, (lpCustDic+Count)->DicTitle, "spelledt.ini");
  335.         WritePrivateProfileInt("Custom", GetCustOpts, (lpCustDic+Count)->Options, "spelledt.ini");
  336.             }
  337.         GlobalUnlock(CheckWord.hCustomDics);
  338.         GlobalFree(CheckWord.hCustomDics);
  339.  
  340.             // finish
  341.             return 0;
  342.  
  343.         case MLC_SETUPWORDS:
  344.             // Build the checkword block
  345.             CheckWord.wSizeOfBlock     = sizeof(CHECKWORD);
  346.             CheckWord.hWndParent       = hWnd;  // window that msg are sent to
  347.             CheckWord.hInstance        = g.hInst;
  348.             CheckWord.lpOptionsDlg     = "SPELTEST_OPTIONSBOX";
  349.             CheckWord.CheckWordOptions = CWO_ALLOWCHANGE    // Do display the box if a word not found
  350.                                        | CWO_CHECKMULTIPLE  // Send GETNEXT messages
  351.                                        | CWO_USEOPTIONSHOOK // Do use the options hook
  352.                                        | CWO_USECUSTOMOPTIONSDLG // and use our dialog box
  353.                                        | CWO_NOHELP         // No help available
  354.                                     // | CWO_UNDO           // not needed
  355.                                        | CWO_AUTOSUGGEST;    // Please auto suggest
  356.             CheckWord.dwCustData  = 0; // not used (by this prog, it is still there is you want it)
  357.             CheckWord.fpOptionsHook  = (DLGPROC)MakeProcInstance(DLG_OptionsBox, g.hInst);
  358.  
  359.             // Get the current language from the one selected by spelledt
  360.             GetPrivateProfileString("Options", "Language", "", CheckWord.szLanguage, 13, "spelledt.ini");
  361.  
  362.             // Load custom dictionaries, in this case we will share the ones that are used by
  363.             // spelledt (i.e. the edit box one).
  364.             CheckWord.NumCustom=GetPrivateProfileInt("Custom", "Number", 0, "spelledt.ini");
  365.             CheckWord.CurCustom=GetPrivateProfileInt("Custom", "Current", 0, "spelledt.ini");
  366.             if (CheckWord.NumCustom!=0)
  367.             {
  368.                 CheckWord.hCustomDics = GlobalAlloc(GHND | GMEM_DDESHARE, sizeof(CUSTDIC)*CheckWord.NumCustom);
  369.                 lpCustDic = (LPCUSTDIC)GlobalLock(CheckWord.hCustomDics);
  370.                 for (Count=0; Count<CheckWord.NumCustom; Count++)
  371.                 {
  372.                     itoa(Count, GetCustPath+4, 10);
  373.                     itoa(Count, GetCustName+4, 10);
  374.                     itoa(Count, GetCustOpts+4, 10);
  375.                     GetPrivateProfileString("Custom", GetCustPath, "custom.dic", (lpCustDic+Count)->DicFile, MAXPATH, "spelledt.ini");
  376.                     GetPrivateProfileString("Custom", GetCustName, "Custom", (lpCustDic+Count)->DicTitle, MAXDICTITLE, "spelledt.ini");
  377.                     (lpCustDic+Count)->Options=GetPrivateProfileInt("Custom", GetCustOpts, CD_CHANGED, "spelledt.ini");
  378.                 }
  379.                 GlobalUnlock(CheckWord.hCustomDics);
  380.             }
  381.             // Load the checkchk module.
  382.             // Get the path and try to load the module
  383.             GetPrivateProfileString("Modules", "spellchk", "spellchk.dll", FileName, MAXPATH, "Spelledt.ini");
  384.             hModSpellchk=LoadLibrary(FileName);
  385.             if (hModSpellchk<HINSTANCE_ERROR)
  386.             {
  387.                 MessageBox(hWnd, "Unable to load the module 'spellchk.dll'", "Spell setup", MB_ICONSTOP);
  388.                 return 0;
  389.             }
  390.  
  391.             // Get the address of the function and call it
  392.             (FARPROC)LINK_SPCHK_Options=GetProcAddress(hModSpellchk, "SPCHK_Options");
  393.             if (LINK_SPCHK_Options==NULL)
  394.                 MessageBox(hWnd, "Unable to load the function 'SPCHK_Options', probably due to an incompatable version.  Please check your system for multiple versions of 'spellchk.dll'.", "Spell setup", MB_ICONSTOP);
  395.             else
  396.                 (LINK_SPCHK_Options)(&CheckWord); // spell check the edit box
  397.  
  398.             // Free the module
  399.             FreeModule(hModSpellchk);
  400.  
  401.             // Free ProcInstance for the options hook
  402.             FreeProcInstance(CheckWord.fpOptionsHook);
  403.  
  404.             // Store the language
  405.             WritePrivateProfileString("Options", "Language", CheckWord.szLanguage, "spelledt.ini");
  406.  
  407.             // Save any changes to the custom dics
  408.             lpCustDic = (LPCUSTDIC)GlobalLock(CheckWord.hCustomDics);
  409.             WritePrivateProfileInt("Custom", "Number", CheckWord.NumCustom, "spelledt.ini");
  410.             WritePrivateProfileInt("Custom", "Current", CheckWord.CurCustom, "spelledt.ini");
  411.             for (Count=0; Count<CheckWord.NumCustom; Count++)
  412.             {
  413.                 itoa(Count, GetCustPath+4, 10);
  414.                 itoa(Count, GetCustName+4, 10);
  415.                 itoa(Count, GetCustOpts+4, 10);
  416.                 WritePrivateProfileString("Custom", GetCustPath, (lpCustDic+Count)->DicFile, "spelledt.ini");
  417.                 WritePrivateProfileString("Custom", GetCustName, (lpCustDic+Count)->DicTitle, "spelledt.ini");
  418.                 WritePrivateProfileInt("Custom", GetCustOpts, (lpCustDic+Count)->Options, "spelledt.ini");
  419.             }
  420.             GlobalUnlock(CheckWord.hCustomDics);
  421.             GlobalFree(CheckWord.hCustomDics);
  422.             // finish
  423.             return 0;*/
  424.         }
  425.         break;
  426.  
  427.     case SPELL_GETNEXT:
  428.         // Get the pointer
  429.         lpchkw = (LPCHECKWORD)lParam;
  430.         wIndex = (WORD)lpchkw->dwCustData;
  431.  
  432.         // Have we done all the words?
  433.         if (wIndex>5)
  434.             return FALSE;
  435.  
  436.         // Copy over the word
  437.         lstrcpy(lpchkw->ToCheck, Words[wIndex]);
  438.  
  439.         // increment the count
  440.         lpchkw->dwCustData++;
  441.         return TRUE;
  442.  
  443.     case SPELL_WORDNOTFOUND:
  444.         // Get the pointer
  445.         lpchkw = (LPCHECKWORD)lParam;
  446.  
  447.         // Display the word not found
  448.         wsprintf(Text, "The word %s was not found", lpchkw->ToCheck);
  449.         MessageBox(hWnd, Text, "Test Word", MB_ICONINFORMATION);
  450.         return 0;
  451.  
  452.     case SPELL_WORDCHANGED:
  453.         // Get the pointer
  454.         lpchkw = (LPCHECKWORD)lParam;
  455.         wIndex = (WORD)lpchkw->dwCustData;
  456.  
  457.         // Change the word
  458.         lstrcpy(Words[wIndex-1], lpchkw->Changed);
  459.  
  460.         // Display the word changed
  461.         wsprintf(Text, "The word %s has been changed to %s",
  462.                    lpchkw->ToCheck, lpchkw->Changed);
  463.         MessageBox(hWnd, Text, "Test Word", MB_ICONHAND);
  464.         return 0;
  465.  
  466.     case SPELL_CANUNDO:
  467.         // Just return the bUndo flag
  468.         return bCanUndo;
  469.  
  470.     case SPELL_STOREUNDO:
  471.         // Get the pointer
  472.         lpchkw = (LPCHECKWORD)lParam;
  473.  
  474.         // Yes we can now undo
  475.         bCanUndo=TRUE;
  476.  
  477.         // Store the handle provided by spellchk
  478.         hUndoHandle=(HUNDO)wParam;
  479.  
  480.         // Store the current word being checked
  481.         wUndoIndex=lpchkw->dwCustData-1;
  482.         lstrcpy(szPreviousWord, lpchkw->ToCheck);
  483.         return 0;
  484.  
  485.     case SPELL_UNDOLAST:
  486.         // Get the pointer
  487.         lpchkw = (LPCHECKWORD)lParam;
  488.  
  489.         // Do the undo if we can - see the full example app for
  490.         // more details
  491.         if (bCanUndo)
  492.         {
  493.             // Do the undo
  494.             lstrcpy(Words[wUndoIndex], szPreviousWord);
  495.  
  496.             // Reposition the index to restart at the pervious position
  497.             lpchkw->dwCustData=wUndoIndex;
  498.  
  499.             // Store the undo handle in the dialog result register
  500.             SetWindowLong(lpchkw->hWndDlg, DWL_MSGRESULT, hUndoHandle);
  501.  
  502.             // Since we have undone once we can't do it again
  503.             bCanUndo=FALSE;
  504.         
  505.             // Return a positive answer
  506.             return FALSE;
  507.         }
  508.         return TRUE;
  509.  
  510.     case SPELL_GETCUSTOMDEFPATH:
  511.     lstrcpy((LPSTR)lParam, g.szProgDir);
  512.     return TRUE;
  513.  
  514.     case WM_CLOSE:
  515.     break;
  516.  
  517.     case WM_DESTROY:
  518.     PostQuitMessage(0);
  519.         break;
  520.     }
  521. return DefWindowProc(hWnd, wMsg, wParam, lParam);
  522. }
  523.  
  524. /***************************************************************************************************
  525.  
  526.     LoadCustomDictionaries
  527.     ----------------------
  528.     Read in the information for custom dictionaries
  529.  
  530.     Parameters : DLG standard
  531.     Called by  : Windows OS
  532.     Calls      : Nothing
  533.     Modifies   : Nothing
  534.     Returns    : Nothing
  535.  
  536. ***************************************************************************************************/
  537. #pragma argsused
  538. void LoadCustomDictionaries(LPCHECKWORD lpCheckWord)
  539. {
  540.     LPCUSTDIC           lpCustDic;
  541.     char                GetCustPath[]="Path???";
  542.     char                GetCustName[]="Name???";
  543.     char                    GetCustOpts[]="Opts???";
  544.     char                GetCustLang[]="Lang???";
  545.     int                 Count;
  546.  
  547.     lpCheckWord->NumCustom=GetPrivateProfileInt("Custom", "Number", 0, "spelledt.ini");
  548.     lpCheckWord->CurCustom=GetPrivateProfileInt("Custom", "Current", 0, "spelledt.ini");
  549.     if (lpCheckWord->NumCustom!=0)
  550.     {
  551.         lpCheckWord->hCustomDics = GlobalAlloc(GHND | GMEM_DDESHARE, sizeof(CUSTDIC)*lpCheckWord->NumCustom);
  552.         lpCustDic = (LPCUSTDIC)GlobalLock(lpCheckWord->hCustomDics);
  553.         for (Count=0; Count<lpCheckWord->NumCustom; Count++)
  554.         {
  555.             itoa(Count, GetCustPath+4, 10);
  556.             itoa(Count, GetCustName+4, 10);
  557.             itoa(Count, GetCustOpts+4, 10);
  558.             itoa(Count, GetCustLang+4, 10);
  559.             GetPrivateProfileString("Custom", GetCustPath, "custom.dic", (lpCustDic+Count)->DicFile, MAXPATH, "spelledt.ini");
  560.             GetPrivateProfileString("Custom", GetCustName, "Custom", (lpCustDic+Count)->DicTitle, MAXDICTITLE, "spelledt.ini");
  561.             GetPrivateProfileString("Custom", GetCustLang, "All", (lpCustDic+Count)->DicLanguage, 13, "spelledt.ini");
  562.             (lpCustDic+Count)->Options=GetPrivateProfileInt("Custom", GetCustOpts, CD_CHANGED, "spelledt.ini");
  563.         }
  564.         GlobalUnlock(lpCheckWord->hCustomDics);
  565.     }
  566. }
  567.  
  568. /***************************************************************************************************
  569.  
  570.     SaveCustomDictionaries
  571.     ----------------------
  572.     Read in the information for custom dictionaries
  573.  
  574.     Parameters : 
  575.     Called by  : 
  576.     Calls      : Nothing
  577.     Modifies   : Nothing
  578.     Returns    : Nothing
  579.  
  580. ***************************************************************************************************/
  581. #pragma argsused
  582. void SaveCustomDictionaries(LPCHECKWORD lpCheckWord)
  583. {
  584.     LPCUSTDIC           lpCustDic;
  585.     char                GetCustPath[]="Path???";
  586.     char                GetCustName[]="Name???";
  587.     char                    GetCustOpts[]="Opts???";
  588.     char                GetCustLang[]="Lang???";
  589.     int                 Count;
  590.  
  591.     // Save any changes to the custom dics
  592.     WritePrivateProfileInt("Custom", "Number", lpCheckWord->NumCustom, "spelledt.ini");
  593.     WritePrivateProfileInt("Custom", "Current", lpCheckWord->CurCustom, "spelledt.ini");
  594.     lpCustDic = (LPCUSTDIC)GlobalLock(lpCheckWord->hCustomDics);
  595.     for (Count=0; Count<lpCheckWord->NumCustom; Count++)
  596.     {
  597.            itoa(Count, GetCustPath+4, 10);
  598.            itoa(Count, GetCustName+4, 10);
  599.            itoa(Count, GetCustOpts+4, 10);
  600.         itoa(Count, GetCustLang+4, 10);
  601.            WritePrivateProfileString("Custom", GetCustPath, (lpCustDic+Count)->DicFile, "spelledt.ini");
  602.           WritePrivateProfileString("Custom", GetCustName, (lpCustDic+Count)->DicTitle, "spelledt.ini");
  603.            WritePrivateProfileString("Custom", GetCustLang, (lpCustDic+Count)->DicLanguage, "spelledt.ini");
  604.           WritePrivateProfileInt("Custom", GetCustOpts, (lpCustDic+Count)->Options, "spelledt.ini");
  605.     }
  606.     GlobalUnlock(lpCheckWord->hCustomDics);
  607.     GlobalFree(lpCheckWord->hCustomDics);
  608. }
  609.  
  610. /***************************************************************************************************
  611.  
  612.     DLG_OptionsBox
  613.     --------------
  614.     Function to handle hooking the options box
  615.  
  616.     Parameters : DLG standard
  617.     Called by  : Windows OS
  618.     Calls      : Nothing
  619.     Modifies   : Nothing
  620.     Returns    : Nothing
  621.  
  622. ***************************************************************************************************/
  623. #pragma argsused
  624. BOOL FAR PASCAL _export DLG_OptionsBox(HWND hDlg, UINT msg, WORD wParam, LONG lParam)
  625. {
  626.     switch(msg)
  627.     {
  628.     case WM_COMMAND:
  629.         switch(wParam)
  630.         {
  631.         case ST_DEMOBUTTON:
  632.             MessageBox(hDlg, "You have hit the test button", "Test Word", MB_ICONINFORMATION);
  633.             return FALSE;
  634.         }
  635.     }
  636.     return FALSE;
  637. }
  638.